package com.ay.weixin.fdc.boss.menu.db;

import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import lizar.db.ibatis.Dao;

import com.ay.weixin.fdc.boss.menu.domain.MenuSub;

public class IbatisMenuSubDao extends Dao {

	public List<MenuSub> getSubMenus(long wxproject_id,String parentKey) throws SQLException{
		Map<String,Object> keys=new LinkedHashMap<String,Object>();
		keys.put("parent_key", parentKey);
		keys.put("wxproject_id", wxproject_id);
		return (List<MenuSub>)this.sqlMapper.queryForList("menu_sub.get_sub_menus", parentKey);
	}
	
	public List<MenuSub> getAllByWxprojectId(long wxproject_id) throws SQLException{
		return (List<MenuSub>)this.sqlMapper.queryForList("menu_sub.getAllByWxprojectId",wxproject_id);
	}
	
	public int size(long wxproject_id,String parent_key) throws SQLException{
		Map<String,Object> keys=new LinkedHashMap<String,Object>();
		keys.put("parent_key", parent_key);
		keys.put("wxproject_id", wxproject_id);
		return (Integer)this.sqlMapper.queryForObject("menu_sub.size",keys);
	}
	
	public void insert(MenuSub menu) throws SQLException{
		this.sqlMapper.insert("menu_sub.insert",menu);
	}
	
	public void delete(long wxproject_id,String parent_key,String key) throws SQLException{
		Map<String,Object> keys=new LinkedHashMap<String,Object>();
		keys.put("parent_key", parent_key);
		keys.put("key", key);
		keys.put("wxproject_id", wxproject_id);
		this.sqlMapper.delete("menu_sub.delete",keys);
	}
	
	public int getMaxPos(long wxproject_id,String parent_key) throws SQLException{
		Map<String,Object> keys=new LinkedHashMap<String,Object>();
		keys.put("parent_key", parent_key);
		keys.put("wxproject_id", wxproject_id);
		Integer max=(Integer)this.sqlMapper.queryForObject("menu_sub.getMaxPos",keys);
		if(max==null){
			return 0;
		}
		return max+1;
	}
	
	public void update(MenuSub menu) throws SQLException{
		this.sqlMapper.insert("menu_sub.update",menu);
	}
	
	public boolean exist(long wxproject_id,String parent_key,String key) throws SQLException{
		Map<String,Object> keys=new LinkedHashMap<String,Object>();
		keys.put("parent_key", parent_key);
		keys.put("key", key);
		keys.put("wxproject_id", wxproject_id);
		Object o=this.sqlMapper.queryForObject("menu_sub.exist",keys);
		if(o==null)return false;
		return true;
		
	}
	
	public MenuSub get(long wxproject_id,String pkey,String key) throws SQLException{
		Map<String,Object> keys=new LinkedHashMap<String,Object>();
		keys.put("parent_key", pkey);
		keys.put("key", key);
		keys.put("wxproject_id", wxproject_id);
		return (MenuSub)this.sqlMapper.queryForObject("menu_sub.get",keys);
	}
	
}
